using System;
using GameFramework;
using GameFramework.Event;
using GameFramework.Procedure;
using UnityEngine;
using UnityGameFramework.Runtime;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;
public class Demo7_ProcedureLaunch : ProcedureBase
{
    protected override void OnEnter(ProcedureOwner procedureOwner)
    {
        base.OnEnter(procedureOwner);

        GameEntry.Event.Subscribe(WebRequestSuccessEventArgs.EventId, OnWebRequestSuccess);
        GameEntry.Event.Subscribe(WebRequestFailureEventArgs.EventId, OnWebRequestFailure);
        //获取数据
        string url = "https://gitee.com/sg-cng-xjt/class_-lua/blob/master/Lesson10_Table2.lua";
        GameEntry.WebRequest.AddWebRequest(url, this);


    }

    private void OnWebRequestFailure(object sender, GameEventArgs e)
    {
        Log.Warning("请求失败");
    }

    private void OnWebRequestSuccess(object sender, GameEventArgs e)
    {

        WebRequestSuccessEventArgs ne = (WebRequestSuccessEventArgs)e;
        //获取回应数据
        string responseJson = Utility.Converter.GetString(ne.GetWebResponseBytes());
        Log.Debug($"responseJson:{responseJson}");

    }
}
